package com.oa.framework.acl.url.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.oa.common.mybatis.typehandler.Boolean2Number;
import com.oa.common.tree.TreeNode;
import com.oa.framework.acl.ResourceType;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.List;

/**
 * 系统资源管理domain
 * @author
 */
@Getter
@Setter
@TableName(value = "acl_system_resource")
public class ResourceManagement implements TreeNode<ResourceManagement>, Serializable {
    /**
     * 管理节点Id
     */
    @JsonSerialize(using=ToStringSerializer.class)
    @TableId(value = "management_id" , type = IdType.ASSIGN_ID)
    private Long managementId;
    /**
     * 管理节点名称
     */
    @TableField(value = "management_name")
    private String managementName;
    /**
     * 父级Id
     */
    @JsonSerialize(using=ToStringSerializer.class)
    @TableField(value = "parent_id")
    private Long parentId;
    /**
     * 排序
     */
    @TableField(value = "order_number")
    private int orderNumber;
    /**
     * 所属该管理节点的资源节点
     */
    @TableField(exist = false)
    private List<ResourceNode> nodes;
    /**
     * 父节点
     */
    @TableField(exist = false)
    private ResourceManagement parent;
    /**
     * 管理节点子节点
     */
    @TableField(exist = false)
    private List<ResourceManagement> children;



    @Override
    public ResourceManagement getParent() {
        return this.parent;
    }


    @Override
    public void setParent(ResourceManagement resourceManagement) {
        this.parent = resourceManagement;
    }

    @Override
    public Object getKey() {
        return managementId;
    }

    @Override
    public Object getParentKey() {
        return parentId;
    }

    @Override
    public String getName() {
        return managementName;
    }

    @Override
    public String getNodeType() {
        return ResourceType.management.getType();
    }
    @Override
    public boolean hasLeaf(){
        return CollectionUtils.isEmpty(this.children);
    }




}
